package com.feige.service.impl;

import com.feige.pojo.RolePermission;
import com.feige.dao.RolePermissionMapper;
import com.feige.service.RolePermissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 角色权限表 服务实现类
 * </p>
 *
 * @author feige
 * @since 2020-07-20
 */
@Service
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermission> implements RolePermissionService {

    @Override
    public boolean AssignPermissions(Long roleId, Long[] permissionId) {
        ArrayList<RolePermission> rolePermissions = new ArrayList<>();
        for (Long s : permissionId) {
            RolePermission rolePermission = new RolePermission();

            rolePermission.setRoleId(roleId);
            rolePermission.setPermissionId(s);
            rolePermissions.add(rolePermission);
        }
        return super.saveBatch(rolePermissions);
    }

    @Override
    public List<Long> getPermissionId(Long roleId) {
        return baseMapper.getPermissionId(roleId);
    }
}
